/************************************************************************
 * @user wxl
 * @date 2016/2/28
 * @description  通知组件
 *************************************************************************
 * @copyright by wh  可以提供开源，但如果引用代码需标明出处
 ************************************************************************/
;(function(NS,$){

    NS.Notification = function(){
        var _id ;
        var NotifiWidget = function(){
            this.imgSrc = '';
            this.title = 'title';
            this.content = 'this is content';
        }

        NotifiWidget.prototype.show = function(data){
            var notifiObject =  JSON.parse(data);
            if(notifiObject.title != "" && notifiObject != undefined)
                this.title = notifiObject.title;
            if(notifiObject.content != "" && notifiObject != undefined)
                this.content = notifiObject.content;
            if(notifiObject.imgSrc != "" && notifiObject.imgSrc != undefined)
                this.imgSrc = notifiObject.imgSrc;
            _createNotification({imgSrc: this.imgSrc,title: this.title,content: this.content})
        };

        var _createNotification = function(data){
            var notificationHtml = '<div id="notification" class="ui-notification" ui-widget-type="Notification"></div>';
            var notification = $(notificationHtml).appendTo(document.body);
            _id = notification[0].id;
            var imgHtml = '<div class="ui-notification-image"><img src="'+data.imgSrc+'"></div>';
            $(imgHtml).appendTo(notification);
            var containerHtml = '<div class="ui-notification-container"></div>';
            var container = $(containerHtml).appendTo(notification);
            var titleHtml = '<div class="ui-notification-title">'+data.title+'</div>';
            $(titleHtml).appendTo(container);
            var contentHtml = '<div class="ui-notification-content">'+data.content+'</div>';
            $(contentHtml).appendTo(container);
        }

        var _init = function(){
            var notifiWidget = new NotifiWidget();
            _createNotification({imgSrc: notifiWidget.imgSrc,title: notifiWidget.title,content: notifiWidget.content});
            NS.widgetMgr.registry(_id, notifiWidget);
            var _hidden = function(){
                setTimeout(function(){
                    $('.ui-notification').animate({opacity:'0'},'slow');
                },2000)
            }
            $('.ui-notification').animate({opacity:'1'},2000,_hidden());
        }
        _init();
    }


})(wh.ui,jQuery);